<script setup lang="ts">
import type { FormSubmitEvent } from "#ui/types";

type LoginType = "login" | "register";
// TODO : login with phone

const userStore = useMyUserStore();

definePageMeta({
  layout: "login",
  middleware: ["visitor"],
});
useHead({
  title: "登录",
  meta: [
    {
      name: "description",
      content: "登录页面",
    },
  ],
});
async function onSubmit(event: FormSubmitEvent<LoginSchema>, type: LoginType = 'login') {
  const res = await $fetch(`/api/signs/${type}`, {
    method: "POST",
    body: event,
  });
  console.log("log fin. body:", res);
  userStore.setUser(res.data);

  navigateTo("/");
}
</script>

<template>
  <!-- <UCard title="登录"> -->
  <LoginComp :on-submit="onSubmit" />
  <!-- <LoginRegisterComp :on-submit="onSubmit" /> -->
  <!-- </UCard> -->
</template>

<style scoped>
</style>
